﻿Public Class DmotDevInmueble

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String) As List(Of EmotDevInmueble)
        Dim MotDevInmuebles As List(Of EmotDevInmueble) = Nothing 'Es una coleccion de lista tipado (vendedor)

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_MotDevInmueble_sel", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            MotDevInmuebles = New List(Of EmotDevInmueble)
                            Dim MotDevInmueble As EmotDevInmueble = Nothing 'tipo 
                            Do While dr.Read
                                MotDevInmueble = New EmotDevInmueble( _
                                    dr.GetInt32(dr.GetOrdinal("idMotDevInmueble")), _
                                    dr.GetString(dr.GetOrdinal("descMotDevInmueble")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetInt32(dr.GetOrdinal("idUsuario")))
                                MotDevInmuebles.Add(MotDevInmueble)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return MotDevInmuebles
    End Function
    Public Shared Function SeleccionarTodoXEstado(ByVal descEmpresa As String) As List(Of EmotDevInmueble)
        Dim MotDevInmuebles As List(Of EmotDevInmueble) = Nothing 'Es una coleccion de lista tipado (vendedor)

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_MotDevInmueble_selXEstado", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            MotDevInmuebles = New List(Of EmotDevInmueble)
                            Dim MotDevInmueble As EmotDevInmueble = Nothing 'tipo 
                            Do While dr.Read
                                MotDevInmueble = New EmotDevInmueble( _
                                    dr.GetInt32(dr.GetOrdinal("idMotDevInmueble")), _
                                    dr.GetString(dr.GetOrdinal("descMotDevInmueble")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetInt32(dr.GetOrdinal("idUsuario")))
                                MotDevInmuebles.Add(MotDevInmueble)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return MotDevInmuebles
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal MotDevInmueble As EmotDevInmueble) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_MotDevInmueble_add", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@descMotDevInmueble", SqlDbType.VarChar, 55).Value = MotDevInmueble.descMotDevInmueble
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = MotDevInmueble.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal MotDevInmueble As EmotDevInmueble) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_MotDevInmueble_edit", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idMotDevInmueble", SqlDbType.Int).Value = MotDevInmueble.idMotDevInmueble
                cmd.Parameters.Add("@descMotDevInmueble", SqlDbType.VarChar, 55).Value = MotDevInmueble.descMotDevInmueble
                cmd.Parameters.Add("@estado", SqlDbType.Char, 1).Value = MotDevInmueble.estado
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = MotDevInmueble.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal MotDevInmueble As EmotDevInmueble) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_MotDevInmueble_del", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idMotDevInmueble", SqlDbType.Int).Value = MotDevInmueble.idMotDevInmueble
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = MotDevInmueble.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function

End Class
